
package gui;


import java.util.Collection;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

/**
 * @author luciano
 */
public class TableModel extends AbstractTableModel
{

   private Vector<String> parametros = new Vector<String>();
   private String[] titles = {"Parametros"};

   public TableModel()
   {
   }

   public TableModel(Vector<String> parametros, String[] titles)
   {
      this.parametros = parametros;
      if (titles != null)
         this.titles = titles;
   }

   public void setParametros(Collection<String> parametros)
   {
      this.parametros.removeAllElements();
      this.parametros.addAll(parametros);
      fireTableStructureChanged();
   }

   public void setParametros(Vector<String> parametros)
   {
      this.parametros = parametros;
      fireTableStructureChanged();
   }

   public Vector<String> getParametros()
   {
      return parametros;
   }

   public int getRowCount()
   {
      return this.parametros.size();
   }

   public int getColumnCount()
   {
      return this.titles.length;
   }

   @Override
   public boolean isCellEditable(int rowIndex, int columnIndex)
   {
      return true;
   }

   @Override
   public void setValueAt(Object aValue, int rowIndex, int columnIndex)
   {
      parametros.set(rowIndex, (String) aValue);
      fireTableCellUpdated(rowIndex, columnIndex);
   }

   public Object getValueAt(int rowIndex, int columnIndex)
   {
      return parametros.get(rowIndex);
   }

   public void addParametro(String param)
   {
      if (!parametros.contains(param))
         parametros.add(param);
      fireTableDataChanged();
   }
   
   public void criarNovaLinha(String param)
   {
      parametros.add(param);
      fireTableDataChanged();
   }

   public void remove(String parametro)
   {
      if (parametros.contains(parametro))
      {
         parametros.remove(parametro);
         fireTableDataChanged();
      }
   }

   public String getValuesAt(int index)
   {
      return parametros.get(index);
   }

   public void removeAt(int index)
   {
      parametros.remove(index);
      fireTableDataChanged();
   }

   public void removeAll(int[] sels)
   {
      for (int i = sels.length - 1; i >= 0; i--)
      {
         removeAt(sels[i]);
      }
   }

   @Override
   public Class<?> getColumnClass(int column)
   {
      return getValueAt(0, column).getClass();
   }

   @Override
   public String getColumnName(int column)
   {
      return titles[column];
   }

}
